package com.culture.config.common.aspect;

import java.util.Objects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Aspect
@Component
public class ActionLogAspect{

    @Pointcut("@annotation(com.culture.config.common.aspect.ActionLog)")
    public void logPointcut(){
        log.info("logPointcut ref");
    }

    @AfterReturning(pointcut = "logPointcut()", returning = "result")
    public void doAfterReturn(JoinPoint joinPoint, Object result) {
        Signature singObj = joinPoint.getSignature();
        log.info("doAfterReturn:{}",singObj.getName());
        if(Objects.nonNull(result)){
            log.info("doAfterReturn:{}",result.toString());
        }
    }
}